<template>
    <view class="nav-container" :class="navClass" :style="{ background: bgColor }">
      <view class="nav-back-icon" v-if="backIcon" @click="goBack">
        <text :style="{ color: backIconColor }">⇐</text>
      </view>
      <view class="nav-title" :style="{ color: titleColor }">
        {{ title }}
      </view>
    </view>
  </template>
  
  <script>
  export default {
    name: "Nav",
    props: {
      // 自定义类名
      navClass: {
        type: String,
        default: "",
      },
      // 导航标题
      title: {
        type: String,
        default: "",
      },
      // 背景颜色，支持渐变色
      bgColor: {
        type: String,
        default: "#fff",
      },
      // 返回按钮颜色
      backIconColor: {
        type: String,
        default: "#000",
      },
      // 是否显示返回按钮
      backIcon: {
        type: Boolean,
        default: false,
      },
    },
    methods: {
      goBack() {
        uni.navigateBack();
      },
    },
  };
  </script>
  
  <style scoped>
  .nav-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20rpx;
    height: 88rpx;
    box-sizing: border-box;
  }
  
  .nav-back-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40rpx;
    height: 40rpx;
  }
  
  .nav-title {
    font-size: 36rpx;
    font-weight: bold;
    text-align: center;
    flex: 1;
  }
  </style>